package tool.data;

import java.util.List;

import tool.analysis.IJavaEntityAnalyser;

	/**
	 * @author jwb09119
	 * @date 2013/11/11
	 * 
	 * Represents a java entity in a program definition
	 */

public abstract class JavaEntity {
	
	private TypeDefinition name;
	private List<TypeDefinition> interfaceTypes;
	private List<TypeDefinition> extendsTypes;
	
	
	public JavaEntity(TypeDefinition type, List<TypeDefinition> interfaceTypes, 
	                                                           List<TypeDefinition> extendsTypes) {

        this.name = type;
        this.interfaceTypes = interfaceTypes;
        this.extendsTypes = extendsTypes;
        
    }


    /**
	 * Get the name of the entity represented by this object
	 * @return - String - in the form 'package*.typeName'
	 */
	public String getName() {
		
		return name.getNameWithPath();
		
	}
	
	
	public List<TypeDefinition> getImplementedInterfaces () {	
		
		return interfaceTypes;
		
	}
	
	
	public List<TypeDefinition> getExtendedTypes () {
	 
	    return extendsTypes;
	    
	}
	
	
	/**
	 * @param otherPackage
	 * @return True if otherPackage matches the package occupied by this entity, otherwise false
	 */
	public boolean hasSamePackageAs(String otherPackage) {
		
		return name.getPath().equals(otherPackage);
		
	}
		
	
	/**
	 * This class is a valid target for the Visitor pattern by analysis objects implementing the
	 * {@link IJavaEntityAnalyser} interface.
	 * @param visitor - the visitor object
	 */
	public abstract void accept (IJavaEntityAnalyser visitor);
	
	
	@Override
	public String toString () {
		
		String reply =  name.getName() + " (" + name.getPath() + ") [" + interfaceTypes.size() +
											" interfaces : extends " + extendsTypes.size() + "]";
		
		for ( TypeDefinition i : interfaceTypes) {
			
			reply += "\n\t Implements: " + i;
			
		}
		
		for ( TypeDefinition e : extendsTypes) {
			
			reply += "\n\t Extends: " + e;
			
		}
		
		
		return reply;
	}



}
